<?php

	class StockController extends  BaseController{

		protected  $_className ="Stock";

		/***********查询普通入库单************/
		public function getStockInList($filter =null, $state = null){
			return $this->getStockList($filter,$state,STOCK_IN);
		}

		/***********查询出库单************/
		public function getStockOutList($filter =null, $state = STOCK_PADDING){
			return  $this->getStockList($filter,$state,OUT);
		}

		/***********查询采购入库单************/
		public function getPurchaseList($filter =null, $state = STOCK_NEW){
			return  $this->getStockList($filter,$state,PURCHASE);
		}

		

		/***********查询销售出库库单************/
		public function getSaleList($filter =null, $state = STOCK_PADDING){
			return  $this->getStockList($filter,$state,SALE);
		}

		/***********查询调拨入库单************/
		public function getTransferInList($filter =null, $state = STOCK_PADDING){
			return  $this->getStockList($filter,$state,TRANSFER_IN);
		}

		/***********查询销售退货入库单************/
		public function getReturnSaleList($filter =null, $state = STOCK_PADDING){
			return  $this->getStockList($filter,$state,SALE_RETURN);
		}

		/***********查询采购退货出库单************/
		public function getPurchaseReturnList($filter =null, $state = STOCK_PADDING){
			return  $this->getStockList($filter,$state,PURCHASE_RETURN);
		}

		/***********通用查询库单************/
		public function getStockList($filter =null, $state=null,$stock_type=STOCK_PADDING,$show_all = false){
			if($filter == null){
				$filter = new SqlFilter();
			}
			
			$filter->addFilter("stock_type",EQUALS,$stock_type);
			//$filter->addFilter("shop_id",EQUALS,Users::GetLoginShopID());
			$filter->addFilter("a.state",EQUALS,$state);
			if(!$show_all){
				$filter->addFilter("a.company_id",EQUALS,Users::GetLoginCommpanyID());
				$filter->attach_express=" and (create_dept_id=".Users::GetLoginShopID()." or target_shop_id=".Users::GetLoginShopID()." )";
			}
			return parent::getEntityList($filter,null,"Stock");
		}

		
		/***********添加普通入库单************/
		public function addStockIn($post_json = null,$transaction = null){
			parent::save($post_json,$transaction,"StockIn");
    	}

    	/***********添加采购入库单************/
    	public function addPurchase($post_json = null,$transaction = null){
			parent::save($post_json,$transaction,"StockPurchase");
    	}

    	/***********添加普通出库单************/
    	public function addStockOut($post_json = null,$transaction = null){
			parent::save($post_json,$transaction,"StockOut");
    	}

    	/***********添加销售出库单************/
    	public function addSale($post_json = null,$transaction = null){
			parent::save($post_json,$transaction,"StockSale");
    	}

    	/***********添加调拨入库单单************/
    	public function addTransferIn($post_json = null,$transaction = null){
			parent::save($post_json,$transaction,"StockTransferIn");
    	}

    	/***********添加销售退货单************/
    	public function addReturnSale($post_json = null,$transaction = null){
			parent::save($post_json,$transaction,"ReturnSale");
    	}

    	/***********添加返厂单************/
    	public function addPurchaseReturn($post_json = null,$transaction = null){
			parent::save($post_json,$transaction,"StockPurchaseReturn");
    	}


    	/***********单据审核************/
    	public function audit($post_json = null,$transaction = null){
			$this->_bean = $this->getPostEntity($post_json,"StockIn");
			$this->_bean->audit();
    	}


    	



  


    	
    	



	}

?>